<template>
    <view class="pub_page pub_page_bg pub_friends_post pub_header_padding">
        <pub-head headerName="friends_post" :headerConfig="headerConfig"></pub-head>
        <div class="pub_page_scroll page_box">
            <textarea v-model="content" class="textarea" placeholder="输入这一刻的想法..." maxlength="1000"></textarea>
            <div class="img_div">
                <div class="li" v-for="(li,key) in pic" :key="key">
                    <div class="img" :style="{backgroundImage:'url('+li+')'}"></div>
                    <text @click="pic.splice(key,1)" class="icon-font-basic icon-b-off-5"></text>
                </div>
                <div class="li li_add" @click="chooseImg" v-if="pic.length<9">
                    <text class="icon-font-basic icon-b-as-1"></text>
                </div>
            </div>
            <div class="bottom_div">
                <div class="txt">无需发布广场需 {{ quanCttDe }} 金币，无需选择</div>
                <div class="txt" @click="isMark == 0 ? isMark = 1 : isMark = 0">
                    <span class="icon-font-basic"
                        :class="isMark == 1 ? 'icon-b-select-6' : 'icon-b-select-4'"></span>是否将此次消息发布至广场，{{ quanAdCtt }} 金币/次
                </div>
                <div class="pub_btn" @click="toSubmit()">确认发布</div>
            </div>
        </div>
    </view>
</template>

<script>
export default {
    data() {
        return {
            pagescrollTop: 0,
            headerConfig: {
                title: '发布',//标题栏内容
                left_type: 3,
            },

            isMark: 0,//是否同步到广场
            pic: [],
            content: "",

            quanAdCtt: 0,
            quanCttDe: 0,
        };
    },
    onLoad() {
        this.getConfig();
    },
    methods: {
        async getConfig() {
            let configRes = await getApp().getConfigList();
            this.quanAdCtt = configRes.quanAdCtt;
            this.quanCttDe = configRes.quanCttDe;
        },
        async chooseImg() {
            const that = this;
            let num = 9 - this.pic.length;
            getApp().imgUpload(num, (list) => {
                console.log('list:', list);
                that.pic = that.pic.concat(list);
            })
        },
        async toSubmit() {
            if (!this.content.trim() && this.pic.length == 0) {
                this.$comFun.toast('说点什么吧');
                return;
            }
            this.$comFun.openLoading();
            const res = await this.$request.post('quan/publishContent', {
                isMark: this.isMark,//是否同步到广场
                pic: this.pic.join(","),
                content: this.content
            });
            // console.log(res);
            this.$comFun.closeLoading();
            if (res.code == 200) {
                this.$comFun.toast('发布成功');
                uni.$emit("friendsPostBack");
                setTimeout(() => {
                    this.$comFun.closeWin();
                }, 1000)
            } else {
                this.$comFun.toast(res.message);
            }
        }
    },
};
</script>

<style lang="scss" scoped>
@import "@/common/css/square.scss";
</style>
